import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class DriverForTagsPuntuations 
{
	static String tagFile;
	static String puncFile;
	static String fileName;
	static String pattern = "(.*?)(/)([^\\s]*)";
	
	static HashSet<String> tags = new HashSet<String>();
	static HashSet<String> punctuations = new HashSet<String>();
	
	public static void main(String args[]) throws IOException
	{
		fileName = args[0];
		tagFile = args[1];
		puncFile = args[2];
		processInputFile();
		outputTagPuncs();
		
		
	}
	
	public static void processInputFile() throws IOException
	{
		FileReader fr = new FileReader(fileName);
		BufferedReader br = new BufferedReader(fr); 
		String s;
		Pattern r = Pattern.compile(pattern);
		String tagPunc;
		
		while((s = br.readLine()) != null) 
		{ 
		      Matcher m = r.matcher(s);
		      while (m.find( )) {
		        
		    	  tagPunc = m.group(3) ;
		    	  if(tagPunc.matches(Driver.tagPatten)) //it's a tag
		    	  {
		    		  if(!tags.contains(tagPunc))
		    			  tags.add(tagPunc);
		    	  }
		    	  else if(tagPunc.matches("\\.|,|:|;|''"))
		    	  {
		    		  if(!punctuations.contains(tagPunc))
		    			  punctuations.add(tagPunc);
		    	  }
		    	  else
		    	  {
		    		  System.out.println("Something unrecognizable: " + tagPunc);
		    		  //System.out.println("line " + s);
		    	  }
		      }
		      
		} 
		fr.close(); 
	}
	
	public static void outputTagPuncs() throws IOException
	{
		FileWriter fw = new FileWriter(tagFile);
		BufferedWriter bw = new BufferedWriter(fw); 
	
		for(String s:tags)
		{
			bw.write(s + "\n");
		}
		
		FileWriter fw2 = new FileWriter(puncFile);
		BufferedWriter bw2 = new BufferedWriter(fw2); 
	
		for(String s:punctuations)
		{
			bw2.write(s + "\n");
		}
		
		bw.close();
		bw2.close();
	}
}
